var gulp = require("gulp");
var minifycss = require("gulp-minify-css");
var uglify = require("gulp-uglify");
var autoprefixer = require("gulp-autoprefixer");
var notify = require("gulp-notify");
var concat = require("gulp-concat");
var ftp = require("gulp-ftp");

gulp.task("managercss", function()
{
	return gulp.src([
			"public/css/bootstrap.css",
			"public/css/font-awesome.css",
			"public/css/jquery.fileupload.css",
			"public/css/datepicker3.css",
			"public/css/manager/manager.css"

		])
		.pipe(minifycss())
		.pipe(autoprefixer("last 15 version"))
		.pipe(concat("manager.min.css"))
		.pipe(gulp.dest("public/min"))
		.pipe(ftp({
            host: 'cemix.co.nz',
            user: 'cemix',
            pass: 'c3m1xltd',
            remotePath: "/www/new/public/min"
        }));
});

gulp.task("managerjs", function()
{
	return gulp.src([
			// jQuery
			'public/js/jquery-1.9.1.min.js',
			'public/js/jquery-ui-1.10.3.custom.min.js',
			'public/js/jquery.livequery.min.js',
			'public/js/jquery.equalheights.js',
			'public/js/jquery.form.min.js',
			'public/js/jquery.nestedSortable.js',
			'public/js/jquery.iframe-transport.js',
			'public/js/load-image.min.js',
			'public/js/jquery.unveil.js',
			'public/js/canvas-to-blob.min.js',
			'public/js/jquery.fileupload.js',
			'public/js/jquery.fileupload-process.js',
			'public/js/jquery.fileupload-image.js',
			'public/js/jsviews.min.js',

			// Bootstrap
			'public/js/bootstrap.min.js',
			'public/js/bootstrap-datepicker.js',

			// Custom JS
			'public/js/manager/manager.js',
			'public/js/manager/pages.js',
			'public/js/manager/products.js',
			'public/js/manager/productcategories.js',
			'public/js/manager/productfiletypes.js',
			'public/js/manager/productimagetypes.js',
			'public/js/manager/projects.js',
			'public/js/manager/news.js',
			'public/js/manager/videos.js',
			'public/js/manager/jobs.js'
		])
		.pipe(uglify())
		.pipe(concat("manager.min.js"))
		.pipe(gulp.dest("public/min"))
		.pipe(ftp({
            host: 'cemix.co.nz',
            user: 'cemix',
            pass: 'c3m1xltd',
            remotePath: "/www/new/public/min"
        }));
});

gulp.task("frontendcss", function()
{
	return gulp.src([
			"public/css/bootstrap.css",
			"public/css/font-awesome.css",
			"public/css/frontend/superfish.css",
			'public/css/frontend/navbar.css',
			"public/css/frontend/frontend.css"
		])
		.pipe(minifycss())
		.pipe(autoprefixer("last 15 version"))
		.pipe(concat("frontend.min.css"))
		.pipe(gulp.dest("public/min"))
		.pipe(ftp({
            host: 'cemix.co.nz',
            user: 'cemix',
            pass: 'c3m1xltd',
            remotePath: "/www/new/public/min"
        }));
});

gulp.task("frontendjs", function()
{
	return gulp.src([
			// jQuery
			'public/js/jquery-1.9.1.min.js',
			'public/js/masonry.pkgd.js',
			//'public/js/jquery-ui-1gulp.10.3.custom.min.js',
			'public/js/jquery.livequery.min.js',
			//'public/js/jquery.equalheights.js',
			//'public/js/jquery.form.min.js',
			//'public/js/jquery.nestedSortable.js',
			//'public/js/jquery.iframe-transport.js',
			//'public/js/load-image.min.js',
			//'public/js/jquery.unveil.js',
			//'public/js/canvas-to-blob.min.js',
			//'public/js/jquery.fileupload.js',
			//'public/js/jquery.fileupload-process.js',
			//'public/js/jquery.fileupload-image.js',
			//'public/js/jsviews.min.js',

			// Bootstrap
			'public/js/bootstrap.min.js',
			//'public/js/bootstrap-datepicker.js',

			// Custom JS
			'public/js/frontend/hoverintent.js',
			'public/js/frontend/superfish.js',
			'public/js/frontend/frontend.js'
		])
		.pipe(uglify())
		.pipe(concat("frontend.min.js"))
		.pipe(gulp.dest("public/min"))
		.pipe(ftp({
            host: 'cemix.co.nz',
            user: 'cemix',
            pass: 'c3m1xltd',
            remotePath: "/www/new/public/min"
        }));
});

gulp.task("watch", function()
{
	gulp.watch("public/css/manager/*.css", ["managercss"]);
	gulp.watch("public/css/frontend/*.css", ["frontendcss"]);
	gulp.watch("public/js/manager/*.js", ["managerjs"]);
	gulp.watch("public/js/frontend/*.js", ["frontendjs"]);
});

gulp.task("default", ["managercss", "frontendcss", "managerjs", "frontendjs", "watch"]);